1550B Maximum Cost Deletion codeforces solution in cpp
by ujjal roy
#include<bits/stdc++.h>
using namespace std;
main()
{
int n,a,b,zc=0,oc=0,i,r,t;
cin>>t;
while(t--)
{
zc=0;
oc=0;
string s;
cin>>n>>a>>b;
cin>>s;
if(b>=0)
{
r=n*a+n*b;
cout<<r<<endl;;
}
else
{
for(i=0;i<n;i++)
{
if(s[i]=='0')
{
while(s[i]=='0') i++;
i--;
zc++;
}
}
for(i=0;i<n;i++)
{
if(s[i]=='1')
{
while(s[i]=='1') i++;
i--;
oc++;
}
}
r=n*a+b*(min(zc,oc)+1);
cout<<r<<endl;;
}
}
return 0;
}
0 Comments